#include <iostream>
#include <pthread.h>
#include <unistd.h>
#include <cstdio>
#include <string>

using namespace std;

void *threadRun(void *arg)
{
    const string name = (char *)arg;
    while (true)
    {
        cout << name << ",pid: " << getpid() << "\n"
             << endl;
        sleep(1);
    }
}
int main()
{
    pthread_t tid[5];
    char name[64];
    for (int i = 0; i < 5; i++)
    {
        snprintf(name, sizeof(name), "%s-%d", "thread", i);
        pthread_create(&tid[i], nullptr, threadRun, (void *)name);
        sleep(1);
    }

    while (true)
    {
        cout << "main thread, pid" << getpid() << endl;
        sleep(1);
    }
    return 0;
}